/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rie06.openvoip.client.IHM.communication;

import com.rie06.openvoip.client.Contact;
import java.awt.Color;
import java.awt.Dimension;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import javax.swing.JPanel;
import org.apache.log4j.Logger;

/**
 *
 * @author Sylvain
 */
public class PanelDialog extends JPanel {

    private WindowDialog dialogWindow;
    private CommunicationController communicationController;
    private PanelContactConversation panelContactConversation;
    private static final Logger logger = Logger.getLogger(PanelDialog.class);

    public PanelDialog(WindowDialog dialogWindow, CommunicationController communicationController) {

        this.dialogWindow = dialogWindow;
        this.communicationController = communicationController;
        this.setPreferredSize(new Dimension(340, 700));
        this.setBackground(Color.blue);

    }

    public void update() {

        this.removeAll();

        HashMap m = (HashMap) dialogWindow.getConversation().getContactList();
        for (Iterator it = m.entrySet().iterator(); it.hasNext();) {
            Map.Entry<UUID, Contact> entry = (Map.Entry<UUID, Contact>) it.next();

            UUID uuid = entry.getKey();
            Contact contact = entry.getValue();

            PanelContactConversation panelContactConversation = new PanelContactConversation(communicationController, this, contact);

            this.add(panelContactConversation);

            if (dialogWindow.getConversation().getContactListCall().containsKey(contact.getUuid())) {
               panelContactConversation.setColor(Color.GREEN);
           }
            
        }

        this.repaint();
        this.revalidate();

    }

    public CommunicationController getCommunicationController() {
        return communicationController;
    }

    public WindowDialog getDialogWindow() {
        return dialogWindow;
    }

    public PanelContactConversation getPanelContactConversation() {
        return panelContactConversation;
    }
}
